<?php
/*==========================================================================*\
| AGRIVIET - CONTENT MANAGERMENT SYSTEM						
\*==========================================================================*/



if (isset($_POST['butSave'])) {
	$published = $_POST['published'];
	$email = trim($_POST['email']);
	$name = trim($_POST['name']);
	$mess = trim($_POST['mess']);
	
	$err="";	
	if ($email=="") $err .="Xin nhập email<br>";	
	if ($name =="") $err .="Xin nhập name<br>";	
	if ($mess =="") $err .="Xin nhập nội dung<br>";	

	
	if ($err==''){
		/* Cap nhat hoac them moi */
		if (!empty($_POST['id'])) {
			$oldid = $_POST['id'];
			$sql = "update comment set published='".$published."',email='".$email."',";
			$sql.= "name='".$name."',mess='".$mess."'where id='".$oldid."'";

		}else {
			// Insert data
			$sql = "insert into news (email,alias,catlink,intro,mess,published,hit,date_add,catid)";
			$sql.= "values ('".$email."','".$alias."',";
			$sql.= "'".$catlink."','".$intro."','".$mess."','".$published."','".$hit."','".$date_add."','".$catid."')";
		}
		/* EOF - Cap nhat hoac them moi */
		if(mysql_query($sql)){ // Neu thuc hien query thanh cong
		
			if(empty($_POST['id'])) $oldid = mysql_insert_id();
			
			/*if(!empty($_POST['id'])){
			// upldate
				foreach ($_POST['email'] as $langid => $email){		
						$intro = trim($_POST['intro'][$langid]);
						$mess = trim($_POST['mess'][$langid]);		
						$sql = "update news_des set email='".$email."',intro='".$intro."',mess='".$mess."'";
						$sql .= "where id='".$oldid."' and  languages_id='".$langid."'";
						mysql_query($sql);
					}	
			} else {
			// Insert			
				foreach ($_POST['email'] as $langid => $email){						
					$sql = "insert into news_des (id,languages_id,email,intro,mess)";
					$sql .= "values('".$oldid."','".$langid."','".$email."','".$intro."','".$mess."')";
					mysql_query($sql);
				}	
			}*/
	
		// Eof Upload image
		} // Neu thuc hien Query thanh cong
		else {
			$err =  "Không th&#7875; c&#7853;p nh&#7853;t";
		}
		
	} // if ($err=='')
	
	if ($err==''){
	$res = $db->query("SELECT * FROM categories WHERE parent_id=50");
	while($r=$db->fetchNextObject($res)){
	$strCat .='catid='.$r->id.' or ';
	}
	$strCat=$strCat.' catid=50';
	$strSQL = "SELECT * from news WHERE $strCat order by date_add DESC limit 7";
	echo homelist($strSQL,'../modules/html/news.htm');
	
	$strCat='';
	
	$res = $db->query("SELECT * FROM categories WHERE parent_id=36");
	while($r=$db->fetchNextObject($res)){
	$strCat .='catid='.$r->id.' or ';
	}
	$strCat=$strCat.' catid=36';
	$strSQL = "SELECT * from news WHERE $strCat order by date_add DESC limit 7";
	echo homelist($strSQL,'../modules/html/tutorial.htm');
	
	 echo '<script>window.location="index.php?act=comment&catid='.$_REQUEST['catid'].'&code=1"</script>';
	 } 	else {
	  echo "<p align=center class='red'>".$err."</p>";
	  }

} 
		
 action('Comment'); // Tieu de trang


	if (isset($_GET['id'])){
	$result=mysql_query("SELECT * FROM comment WHERE id=$id");
	$row=mysql_fetch_object($result);
	$image=$row->image;
	$imagelarge=$row->imagelarge;
	$email=$row->email;
	$name=$row->name;
	$mess=$row->mess;
	$published=$row->published;
	}
	 $parent=$_GET['catid'];
	?>	
  <table border="0" cellpadding="3" cellspacing="3" bordercolor="#CCCCCC">
<form action="" method="post" enctype="multipart/form-data" name="form1">
<input type="hidden" name="act" value="comment_m">
<input type="hidden" name="id" value="<? echo $_REQUEST['id']; ?>">
<input type="hidden" name="page" value="<? echo $_REQUEST['page']; ?>">
    <tr>
      <td align="right" valign="top">email</td>
      <td>
	  <div style="margin:3px 0">
	    <input name="email" type="text" style="width:95%" value="<?=$email;?>" size="50">
	  </div>	   </td>
    </tr>
    <tr>
      <td align="right" valign="top">Name</td>
      <td valign="top" ><span style="margin:3px 0">
        <input name="name" type="text" style="width:95%" value="<?=$name;?>" size="50" />
      </span></td>
    </tr>
    <tr>
      <td align="right" valign="top">Mess text </td>
      <td valign="top" >
	  <textarea name="mess" rows="5" id="mess" style="width:95%"><?=$mess;?></textarea>	</td>
    </tr>
	<tr>
	  <td align="right">Published</td>	  
	  <td ><input name="published" type="checkbox" id="published" value="1" checked="<? if ($published>0) echo 'checked' ?>" /></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><label>
        <input name="butSave" type="submit" id="butSave" value="   Cập nhật  " class="button">
        
      </label></td>
    </tr></form>
</table>

